{layout name="../../admin/view/layout/main" /}
{:breadcrumb(['UI 示例:example/layout/index', '下拉插件:example/select/index', '联动插件'])}

<div class="row">

    <div class="col-lg-12">
      <div class="card">
        <header class="card-header">
          <div class="card-title">联动插件 bootstrap-selectN</div>
        </header>
        <div class="card-body">
        
          <p>该插件是基于layui的一个插件selectN.js，这里去掉了原有layui的东西，根据基本的使用需求做了些修改而改成的一个jquery插件。</p>
        
        <p><strong>简单使用</strong></p>
        <div class="mb-3">
          <div id="example-1"></div>
        </div>
        <pre>var catIns1 = $('#example-1').bootstrapSelectN({
  data: catData,
});</pre>
        <p><strong>设置空值项提示</strong></p>
        <div class="mb-3">
          <div id="example-2"></div>
        </div>
        <pre>var catIns2 = $('#example-2').bootstrapSelectN({
  data: catData,
  placeholder: ['设置一', '设置二', '设置三'],
});</pre>
        <p><strong>设置宽度</strong></p>
        <p>可单个使用，也可使用数组形式。<code>['120px', '190px', '200px']</code></p>
        <div class="mb-3">
          <div id="example-3"></div>
        </div>
        <pre>var catIns3 = $('#example-3').bootstrapSelectN({
  data: catData,
  width: '190px', // 设置实际长度或者百分比长度，当form表单的class="form-horizontal"时可以使用col-*
});</pre>
        
        <p><strong>表单中使用</strong></p>
        <form class="form-horizontal">
          <div class="mb-3 row">
            <label class="col-md-12 form-label" for="title">标题</label>
            <div class="col-sm-12">
              <input type="email" class="form-control" id="title" placeholder="Email">
            </div>
          </div>
          <div class="mb-3 row">
            <label class="col-md-12 form-label">分类</label>
            <div id="example-4" class="col-md-12 row"></div>
          </div>
        </form>
        <pre>var catIns4 = $('#example-4').linkageSelect({
  data: catData,
  width: 'col-md-3',
});</pre>
        <p><strong>url地址获取json数据</strong></p>
        <div class="mb-3">
          <div id="example-5"></div>
        </div>
        <pre>var catIns5 = $('#example-5').bootstrapSelectN({
  data: 'data_selectN_json.php',
});</pre>
        <p><strong>指定已选中值</strong></p>
        <div class="mb-3">
          <div id="example-6"></div>
        </div>
        <pre>var catIns6 = $('#example-6').bootstrapSelectN({
  data: catData,
  selected: [6,10,11,20,21,22]
});</pre>
        
        <button class="btn btn-default">获取值</button>
        <pre id="log" class="mt-2"></pre>
        
        </div>
      </div>
  </div>

</div>

<script>
    $(function(){
        var catData = [{"id":1,"name":"周边旅游","children":[{"id":24,"name":"广东","status":0,"children":[{"id":7,"name":"广州"},{"id":23,"name":"潮州"}]}]},{"id":5,"name":"国内旅游","children":[{"id":8,"name":"华北地区","children":[{"id":9,"name":"北京"}]}]},{"id":6,"name":"出境旅游","children":[{"id":10,"name":"东南亚","children":[{"id":11,"name":"马来西亚","children":[{"id":20,"name":"沙巴","children":[{"id":21,"name":"美人鱼岛","children":[{"id":22,"name":"潜水"}]}]}]}]}]}];

var catIns1 = $('#example-1').bootstrapSelectN({
    data: catData,
});
  
var catIns2 = $('#example-2').bootstrapSelectN({
    data: catData,
    placeholder: ['设置一', '设置二', '设置三'],
});
  
var catIns3 = $('#example-3').bootstrapSelectN({
    data: catData,
    width: '190px', // 设置实际长度或者百分比长度，当form表单的class="form-horizontal"时可以使用col-*
});
  
var catIns4 = $('#example-4').bootstrapSelectN({
    data: catData,
    width: 'col-md-3',
});

var catIns5 = $('#example-5').bootstrapSelectN({
    data: "{:url('example/select/data')}",
    placeholder: ['请选择省', '请选择市', '请选择县/区'],
});

var catIns6 = $('#example-6').bootstrapSelectN({
    data: catData,
    selected: [6,10,11,20,21,22]
});

$('.btn').on('click', function(){
    var logbox = $('#log');
    logbox.append('catIns1 当前选中的值：', catIns1.values+'\n');
    logbox.append('catIns2 当前选中的值：', catIns2.values+'\n');
    logbox.append('catIns3 当前选中的值：', catIns3.values+'\n');
    logbox.append('catIns4 当前选中的值：', catIns4.values+'\n');
    logbox.append('catIns5 当前选中的值：', catIns5.values+'\n');
    logbox.append('catIns6 当前选中的值：', catIns6.values+'\n');
});
    });
</script>